package com.tiecode.plugin.regex.action;

import com.tiecode.develop.component.api.option.TieItem;
import com.tiecode.develop.component.api.option.TieMenu;
import com.tiecode.develop.component.widget.option.TieMenuItem;
import com.tiecode.develop.util.firstparty.android.ColorUtils;
import com.tiecode.develop.util.firstparty.image.DrawableUtils;
import com.tiecode.plugin.PluginEnvironment;
import com.tiecode.plugin.action.page.code.CodePageAction;
import com.tiecode.plugin.api.project.config.RunConfiguration;
import com.tiecode.plugin.regex.R;

import java.net.URI;

public class RegexCodePageAction extends CodePageAction {
    private final static String TITLE_REGEX = "正则测试";

    @Override
    public void onCreate() {
        super.onCreate();
        registerRunConfiguration(new RunAllTestConfig());
    }

    @Override
    public void onCreateToolMenu(TieMenu menu) {
        menu.addItem(
                new TieMenuItem(
                        TITLE_REGEX,
                        DrawableUtils.getDrawable(
                                PluginEnvironment.getContext(this),
                                R.drawable.ic_regex
                        )
                )
        );
    }

    @Override
    public void onToolMenuClick(TieItem item) {
        if (TITLE_REGEX.equals(item.getTitle())) {
            openURI(URI.create(RegexCodeBodyAction.SCHEMA_REGEX_EDIT + ":///" + "正则测试.rmc"));
        }
    }

    class RunAllTestConfig implements RunConfiguration {

        @Override
        public String getId() {
            return "regex-test-all";
        }

        @Override
        public String getName() {
            return "批量正则测试";
        }

        @Override
        public void run() {
            openURI(URI.create(RegexCodeBodyAction.SCHEMA_REGEX_TEST + ":///" + "批量测试.rmt"));
        }
    }
}
